<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>$title,'backList'=>'返回列表']"/>
<div class="layui-fluid">
    <div class="layui-form">
        <div class="layui-form-item">
			<label class="layui-form-label required">应用分类</label>
			<div class="layui-input-inline">
				<select name="cid" lay-verify="">
					<php foreach="$catelist as $key=>$vo">
					  <option value="<{$vo['id']}>" <?php if(!empty($applink)){echo $applink['cid'] == $vo['id']?'selected=""':'';}?>><{$vo['name']}></option>
					</php> 
					</select> 
			</div>
		</div>
        <div class="layui-form-item">
            <label class="layui-form-label required">应用名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" lay-reqtext="应用名称不能为空" placeholder="请输入应用名称"
                    value="<{$applink['name']??''}>" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">链接</label>
            <div class=" layui-col-md4 layui-input-black">
                <input type="text" name="url" lay-verify="required" lay-reqtext="链接不能为空" placeholder="请输入链接"
                    value="<{$applink['url']??''}>" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">图标</label>
            <div class="layui-input-inline" style="width:300px;">
               <input type="text" class="icoSelect" placeholder="选择图标" name="ico" value="<{$applink['ico']??''}>" lay-verify="required" lay-reqtext="图标不能为空">
            </div> <span class="layui-form-mid layui-word-aux" id="iconame"><{$applink['ico']??''}></span>
        </div>        
		<div class="layui-form-item">
            <label class="layui-form-label required">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="sort" lay-verify="required" lay-reqtext="排序数字不能为空" placeholder="请输入排序数字"
                    value="<{$applink['sort']??''}>" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-inline">
			  <input type="radio" name="status" value="1" title="启用" <?php if(!empty($applink) && $applink["status"] ==1){ echo 'checked=""';} ?>>
			  <input type="radio" name="status" value="0" title="禁用" <?php if(!empty($applink) && $applink["status"] ==0){ echo 'checked=""';} ?>>
			</div>
		  </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="<{$applink['id']??''}>">
                <button class="layui-btn" lay-submit lay-filter="saveBtn"><i class="layui-icon">&#x1005;</i><?php echo lang('save');?></button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.define(["iconSelected"],function () {
        var form = layui.form,layer = layui.layer,iconSelected = layui.iconSelected,$ = layui.$;
        form.render();

        iconSelected.render(".icoSelect", {
            event: {
                select(event, data) {
                    $('#iconame').text(data.icon);
                    //console.log("选中的图标数据", { event, data });
                },
            },
        });  

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post('<{CAUrl("applink",ROUTE["act"])}>', data.field, function (res) {
                if (res.status == 1) {
                    layer.msg(res.info, { icon: 1, time: 1000 }, function () {
                        loadMain('<{CAUrl("applink","index")}>');
                    });
                } else {
                    layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
                }
            });
            return false;
        });

    });
</script>